package com.googlecode.droiddip;

/* 
 * 
 * A province is a land (inluding coastal) or sea region on the diplomacy board
 * Currently it is defined by a path of its border. This is wasteful as adjacent provinces
 * will define the same section of path twice. 
 * TODO: create border class and then snip the province's outlines into distinct border between adjacent countries.
 */


import android.graphics.Path;
import android.graphics.Point;
import com.googlecode.droiddip.Border;
import java.util.Vector;
import android.util.Log;
import java.lang.Integer;


public class Province extends Path
{
	public enum Type { LAND, SEA, NEUTRAL }
	
	public String name;
	public String abbreviation;
	public Type type;
	public Point label;
	public Point centre;
	
	public Province (String pName, String pAbbreviation, Type pType, Point pLabel, Border... borders)
	{
		super();
		name = pName;
		abbreviation = pAbbreviation;
		type = pType;
		label = pLabel;
		
		Log.i("Province","Creating province " + pName);
		
		if ( borders.length > 0 )
		{
			Log.i("Border","Adding " + (new Integer(borders.length)).toString() + " borders... ");
			Vector<Point> points = borders[0].getVector();
			for ( int i = 1; i < borders.length; ++i)
				borders[i].join(points);
			
			
			Point point = points.firstElement();
			this.moveTo(point.x, point.y);
			for (int i = 1; i < points.size() ; ++i )
			{
				point = points.get(i);
				this.lineTo(point.x, point.y);
			}
			this.close();
		}
		
		Point topLeft = new Point(borders[0].points[0]);
		Point bottomRight = new Point(borders[0].points[0]);
		for (int i = 0; i < borders.length; ++i ) 
		{
			for (int j = 0; j < borders[i].points.length; ++j )
			{
				Point c = borders[i].points[j];
				if (c.x < topLeft.x) topLeft.x = c.x;
				if (c.y < topLeft.y) topLeft.y = c.y;
				if (c.x > bottomRight.x) bottomRight.x = c.x;
				if (c.y > bottomRight.y) bottomRight.y = c.y;
			}
		}
		centre = new Point((topLeft.x + bottomRight.x) / 2, (topLeft.y + bottomRight.y) / 2);
	}
	
}
